STM32 |
您所在的位置:网站首页 › mcp2515 stm32 › STM32 |
前幾篇有關於CANBus的文章都是利用環回模式去做測試~這一篇會透過Arduino+MCP2515與STM32完成CANBus通訊~ 接線 MEGA2560 & MCP2515 MEGA2560 MCP2515 D52 SCK D53 CS D50 MISO D51 MOSI 5V VCC GND GND MCP2515 & STM32 MCP2515 STM32 L476RG CAN H PA12 CAN L PA11 Arduino這部分有已經寫好的庫可以使用,我是使用連結 這個庫來完成的 這邊要注意MCP2515的Baud Rate設定,這邊設定是8MHZ選擇125k bit/s #include #include struct can_frame canMsg; struct can_frame canMsg1; MCP2515 mcp2515(53); //CSS void setup() { canMsg1.can_id = 0x1876AC23 | CAN_EFF_FLAG; canMsg1.can_dlc = 8; canMsg1.data[0] = 0x05; canMsg1.data[1] = 0x06; canMsg1.data[2] = 0x07; canMsg1.data[3] = 0x08; canMsg1.data[4] = 0x09; canMsg1.data[5] = 0x0A; canMsg1.data[6] = 0x0B; canMsg1.data[7] = 0x0C; while (!Serial); Serial.begin(115200); mcp2515.reset(); mcp2515.setBitrate(CAN_125KBPS,MCP_8MHZ); //mcp2515.setLoopbackMode(); mcp2515.setNormalMode(); Serial.println("********MCP2515&STM32_CAN_Test*********"); Serial.println("********Send Message*********"); mcp2515.sendMessage(&canMsg1); Serial.print(canMsg1.can_id, HEX); Serial.print(" "); Serial.print(canMsg1.can_dlc, HEX); Serial.print(" "); for (int i = 0; i |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |